package com.yy.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yy.pojo.Admin;
import com.yy.service.Impl.AdminServiceImpl;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author young
 * @date 2022/9/5 13:30
 * @description:
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    /** username **/
    private static final String USERNAME ="username" ;
    @Autowired
    private AdminServiceImpl adminService;
    @PostMapping("/login")
    public Object loginStatus(HttpServletRequest request, HttpSession session){
        JSONObject object = new JSONObject();
        String username = request.getParameter(USERNAME);
        String pwd = request.getParameter("pwd");

        long count = adminService.count(new QueryWrapper<Admin>().eq(USERNAME, username).eq("pwd", pwd));
     //   boolean result = adminService.verifyPassword(username, pwd);
        if (count>0){
            object.put("code",1);
            object.put("msg","登陆成功");
            session.setAttribute("username",username);
            return object;
        }else {
            object.put("code",0);
            object.put("msg","用户名或密码错误");
            return object;
        }

    }
    

}
